package com.biostime.qdingding.modules.job;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import com.biostime.qdingding.common.utils.DateUtils;
import com.biostime.qdingding.common.utils.StringUtils;
import com.biostime.qdingding.modules.job.service.AutoClearService;

/**
 * 上课提醒处理类
 * @author phil
 * @version 2015-12-28
 */
@Service
@Lazy(false)
public class CourseTipJob {
	
	@Autowired
	private AutoClearService autoClearService;
	
	protected Logger logger = LoggerFactory.getLogger("autoclear"); //日志对象
	
	private static boolean alive = true; //当前任务是否执行完毕
	private static int CourseCount = 10; //每次读取课程订单数量
	
	@SuppressWarnings("unused")
	private static int Timeout = 0; //任务超时时间
	
	/**
	 * 每天晚上10:10自动扣费后发送上课提醒
	 */
	@Scheduled(cron = "0 10 22 * * ?")  
	public void schedule(){
		
		alive = true;
		Date startOn = new Date();
		logger.info(DateUtils.formatDate(startOn, "yyyy-MM-dd HH:mm:ss") + (" 自动结算--开始"));
		
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		calendar.add(Calendar.DAY_OF_MONTH, 1);
		
		/*while(alive){
			synchronized (CourseTipJob.class) {
				new Thread(new Runnable() {
					@Override
					public void run() {
						synchronized (CourseTipJob.class) {
							
						}
					}
				}).start();
				
				try {
					CourseTipJob.class.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}*/
		
		Date endOn = new Date();
		long time = (endOn.getTime() - startOn.getTime());
		logger.info(DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss") + (" 自动结算--结束") + " 耗时：" + time + " ms");
	}
}
